<template>
    <div style="height: 100vh; overflow: hidden; position: relative">
        <div style="width: 300px; height: 500px; background-color: white; border-radius: 10px;
        margin: 150px auto; padding:50px">
            <div style="margin: 30px; text-align: center; font-size: 30px; font-weight: bold; color: dodgerblue">登 录
            </div>
            <el-form :model="user">
                <el-form-item prop="id">
                    <el-input placeholder="请输入工号" prefix-icon="el-icon-user" size="medium" v-model="user.id"
                              @keyup.enter.native="login"></el-input>
                </el-form-item>
                <el-form-item prop="pwd">
                    <el-input placeholder="请输入密码" show-password prefix-icon="el-icon-lock" size="medium"
                              v-model="user.pwd" @keyup.enter.native="login"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button style="width: 100%" size="medium" type="primary" @click="login">登录</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
import Vue from 'vue';
import {Notify} from 'vant';
// 全局注册
Vue.use(Notify);

export default {
    // eslint-disable-next-line vue/multi-word-component-names
    name: 'index',
    data() {
        return {
            user: {},
        }
    },
    methods: {
        login() {
            for (var id in this.$store.state.users) {
                // console.log(id);
                // console.log(this.$store.state.users[id].pwd, this.user.pwd)
                if (id === this.user.id) {
                    if (this.$store.state.users[id].pwd === this.user.pwd) {
                        // console.log(this.user.pwd);
                        // console.log(this.$store.state.users[id].pwd)
                        //登录标志
                        sessionStorage.logined = true;
                        //
                        sessionStorage.id = this.user.id;
                        sessionStorage.role = this.$store.state.users[id].role;
                        sessionStorage.current = JSON.stringify(this.$store.state.users[id]);
                        //跳转
                        this.$router.push('/');
                    }
                }
            }
            if (!sessionStorage.logined) Notify('工号或密码出错\n请重新输入');
        }
    },

    mounted() {

    }
}
</script>

<style scoped>
.cover {
    width: fit-content;
    background-color: white;
    position: absolute;
    top: 50%;
    left: 50%;
    /*margin: 0;*/
    /*border: 0;*/
    /*padding: 0;*/
    transform: translate(-50%, -50%);
    z-index: 1000;
}
</style>
